//
//  Users.m
//  QuickCure1
//
//  Created by maoge on 16/10/30.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "Users.h"
#import <YYModel.h>

@implementation Users


////告诉系统哪些属性要归档
//- (void)encodeWithCoder:(NSCoder *)aCoder{
//    
//    [aCoder encodeObject:self.true_name forKey:@"true_name"];
//    [aCoder encodeObject:self.head_photo forKey:@"head_photo"];
//    [aCoder encodeObject:self.mobile_number forKey:@"mobile_number"];
//    [aCoder encodeObject:self.user_id forKey:@"user_id"];
//    [aCoder encodeObject:self.height forKey:@"height"];
//    [aCoder encodeObject:self.weight forKey:@"weight"];
//    [aCoder encodeObject:self.province_id forKey:@"province_id"];
//}
//
////告诉系统哪些属性可以获取
//- (instancetype)initWithCoder:(NSCoder *)aDecoder{
//    
//    self = [super init];
//    if (self) {
//        self.true_name = [aDecoder decodeObjectForKey:@"true_name"];
//        self.head_photo = [aDecoder decodeObjectForKey:@"head_photo"];
//        self.mobile_number = [aDecoder decodeObjectForKey:@"mobile_number"];
//        self.user_id = [aDecoder decodeObjectForKey:@"user_id"];
//        self.height = [aDecoder decodeObjectForKey:@"height"];
//        self.weight = [aDecoder decodeObjectForKey:@"weight"];
//        self.province_id = [aDecoder decodeObjectForKey:@"province_id"];
//    }
//    return self;
//}


//告诉系统哪些属性要归档
//存
- (void)encodeWithCoder:(NSCoder *)aCoder{
    unsigned int count = 0;
    Ivar *ivars = class_copyIvarList([self class], &count);
    for (int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];
        const char *name = ivar_getName(ivar);
        NSString *key = [NSString stringWithUTF8String:name];
        id value = [self valueForKey:key];
        [aCoder encodeObject:value forKey:key];
    }
    free(ivars);
}


//告诉系统哪些属性可以获取
//取
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super init]) {
        unsigned int count = 0;
        Ivar *ivars = class_copyIvarList([self class], &count);
        for (int i = 0; i < count; i++) {
            Ivar ivar = ivars[i];
            const char *name = ivar_getName(ivar);
            NSString *key = [NSString stringWithUTF8String:name];
            id value = [aDecoder decodeObjectForKey:key];
            [self setValue:value forKey:key];
        }
        free(ivars);
    }
    return self;
}


- (NSString *)description{
    return [self yy_modelDescription];
}



+ (instancetype)userWithDic:(NSDictionary *)dic{
    Users *user = [[Users alloc] init];
    
    [user setValuesForKeysWithDictionary:dic];
    
    return user;
}


//重写undefine方法
-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
}


@end
